package com.woody.aggregate.shop.enums.es;

import com.woody.aggregate.common.enums.ShopPropertyTypeEnum;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import javax.annotation.Nonnull;
import java.util.Optional;

/**
 * &copy; All rights Reserved
 * ES门店类型
 * @author wénkǎi.zhāng 2025-04-07
 */
@Getter
@RequiredArgsConstructor
public enum EsShopTypeEnum {
    /**
     * 普通门店
     */
    NORMAL(0),

    /**
     * 主门店
     */
    MAIN(1),

    /**
     * 子门店
     */
    CHILD(2),

    /**
     * 商圈
     */
    BD(3);

    /**
     * 门店类型
     */
    private final Integer type;

    public static Optional<EsShopTypeEnum> fromType(@Nonnull Integer type) {
        for (EsShopTypeEnum value : values()) {
            if (value.getType().equals(type)) {
                return Optional.of(value);
            }
        }

        return Optional.empty();
    }

    /**
     * 数据库门店类型转ES门店类型
     *
     * @param propertyTypeEnum
     * @return
     */
    public static Optional<EsShopTypeEnum> fromShopPropertyType(@Nonnull ShopPropertyTypeEnum propertyTypeEnum) {
        if (ShopPropertyTypeEnum.NORMAL.equals(propertyTypeEnum)) {
            return Optional.of(EsShopTypeEnum.NORMAL);
        }

        if (ShopPropertyTypeEnum.MAIN.equals(propertyTypeEnum)) {
            return Optional.of(EsShopTypeEnum.MAIN);
        }

        if (ShopPropertyTypeEnum.CHILD.equals(propertyTypeEnum)) {
            return Optional.of(EsShopTypeEnum.CHILD);
        }

        return Optional.empty();
    }
}
